﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XW.Utils
{
    public static class JObjectExt
    {       /// <summary>
            /// 判断是否true
            /// </summary> 
        public static bool IsNotNullAndEmpty(this JObject b,string key)
        {
            if (b.ContainsKey(key)) {
                var value = b[key].Value<string>();
                return value.IsNotNullAndEmpty(); 
            }
            return false;
        }
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="b">The b.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public static string getStr(this JObject b,string key)
        {
            if (b.ContainsKey(key))
            {
                return b[key].Value<string>();
            }
            return null;
        }

        public static int? getInt(this JObject b, string key)
        {
            if (b.ContainsKey(key))
            {
                return b[key].Value<int?>();
            }
            return null;
        }
    }
}
